#include <stdint.h>
#include <fcntl.h>

typedef struct tyn_exsorter_node_t {
    void *data;
    size_t block_idx;
} tyn_exsorter_node_t;

typedef struct tyn_exsorter_t {
    uint32_t type;
    char *buffer;
    size_t buffer_size;
    char *buffer_cur;
    size_t item_size;
    size_t num_total_items;
    size_t max_num_items;
    size_t num_items;
    size_t num_blocks;
    int (* sort_func)(void *, size_t, size_t);
    int (* node_cmp_func)(tyn_exsorter_node_t *, tyn_exsorter_node_t *);
    int fd_tmp;
    int fd_write;
    size_t output_buffer_size;
    size_t sort_buffer_size;
} tyn_exsorter_t;

tyn_exsorter_t* tyn_exsorter_create(char *, size_t, size_t, int (*)(void *, size_t, size_t), int (*)(tyn_exsorter_node_t*, tyn_exsorter_node_t *), int);
int tyn_exsorter_destroy(tyn_exsorter_t *);
int tyn_exsorter_add(void *, tyn_exsorter_t *);
int tyn_exsorter_flush(tyn_exsorter_t *);
//int tyn_exsorter_sort(tyn_exsorter_t *, void *context, int (* progress_callback)(size_t, size_t, int));
int tyn_exsorter_sort(tyn_exsorter_t *, void *, int (*)(void *, size_t, void*, int), int (*)(size_t, size_t, int));
